-- 格式要UTF8-BOM
local TWaryLua = require "TWaryLua";
local all_info = require "all_info";

-- 生成ServerParameter.ini
local function genServerParameter()

    local content = ""
    content = content .. "[Correspond]\n"
    content = content .. "ConnectMax=512\n"
    content = content .. "ServicePort=6005\n"
    content = content .. "[PersonalRoom]\n"
    content = content .. "ConnectMax=512\n"
    content = content .. "ServicePort=6004\n"
    content = content .. "[ChatServer]\n"
    content = content .. "MaxPlayer=4096\n"
    content = content .. "ServicePort=6001\n"
    content = content .. "[LogonServer]\n"
    content = content .. "DelayList=1\n"
    content = content .. "ConnectMax=10240\n"
    content = content .. "ServicePort=6002\n"
    content = content .. "[GameServer]\n"
    content = content .. "BindMachineID=0\n"
    content = content .. "ServiceMachine="..  TWaryLua.XorEncrypt( TWaryLua.ServerGUID() ).."\n"  -- 系统验证码
    content = content .. "[ServerInfo]\n"
    content = content .. "ServiceName=".. TWaryLua.XorEncrypt("Server") .."\n"
    content = content .. "ServiceAddr=".. TWaryLua.XorEncrypt("127.0.0.1") .. "\n"--
    content = content .. "CorrespondAddr=".. TWaryLua.XorEncrypt(all_info.web_address_private) .."\n" -- web内网
    content = content .. "[PlatformDB]\n"
    content = content .. "DBPort=".. 1433 .."\n" -- 数据库端口
    content = content .. "DBAddr=".. TWaryLua.XorEncrypt(all_info.sql_address_private) .."\n"
    content = content .. "DBUser=" .. TWaryLua.XorEncrypt("cpp_app") .. "\n"
    content = content .. "DBPass=" .. TWaryLua.XorEncrypt(all_info.cpp_pass) .. "\n"
    content = content .. "[TreasureDB]\n"
    content = content .. "DBPort=".. 1433 .."\n" -- 数据库端口
    content = content .. "DBAddr=".. TWaryLua.XorEncrypt(all_info.sql_address_private) .."\n"
    content = content .. "DBUser=" .. TWaryLua.XorEncrypt("cpp_app") .. "\n"
    content = content .. "DBPass=" .. TWaryLua.XorEncrypt(all_info.cpp_pass) .. "\n"
    content = content .. "[AccountsDB]\n"
    content = content .. "DBPort=".. 1433 .."\n" -- 数据库端口
    content = content .. "DBAddr=".. TWaryLua.XorEncrypt(all_info.sql_address_private) .."\n"
    content = content .. "DBUser=" .. TWaryLua.XorEncrypt("cpp_app") .. "\n"
    content = content .. "DBPass=" .. TWaryLua.XorEncrypt(all_info.cpp_pass) .. "\n"
    content = content .. "[GoogleValidate]\n"
    content = content .. "GoogleSourceKey=".. TWaryLua.XorEncrypt(all_info.google_pass).."\n"

    -- 把配置保存到两个地方
    TWaryLua.SaveToFile("C:\\Users\\Administrator\\Desktop\\config\\ServerParameter.ini", content)
end;



local function changeXML()
    local content = [[<?XML Version"1.0" Encoding="UTF-8"?>
<!--进程配置信息-->
<ProcessConfig>
    <!--创建窗口-->
    <cbNewWindow>1</cbNewWindow>
    <!--显示窗口-->
    <cbShowWindow>1</cbShowWindow>
</ProcessConfig>

<!--服务参数信息-->
<ServerConfig>
    <!--启动类型(0:测试类型,1:测试客户端,2:测试服务端,3:普通代理,4:网狐代理,)-->
    <wStartType>4</wStartType>
    <!--监听端口(服务监听的端口号,作为服务启动时有效)-->
    <wListenPort>9999</wListenPort>
    <!--连接地址(连接地址的IP或者域名,作为客户端或者代理启动时有效)-->
    <szConnectAddress>]] .. all_info.web_address_private .. [[</szConnectAddress>
    <!--连接端口(连接地址的端口号,作为客户端或者代理启动时有效)-->
    <wConnectPort>6005</wConnectPort>
    <!--连接数量(创建连接的数目,作为客户端启动时有效)-->
    <wConnectCount>0</wConnectCount>
    <!--服务标识(自定义标识信息,用于对象区分,保留字段)-->
    <dwServerType>666</dwServerType>
    <!--工作线程(工作线程数量)-->
    <wThreadCount>4</wThreadCount>
    <!--检测间隔(检测时间间隔,单位为毫秒)-->
    <dwDetectTime>10000</dwDetectTime>
    <!--协议类型(TCP/IP协议类型,0:IPV4,1:IPV6,2:IPV4+IPV6)-->
    <wProtocol>0</wProtocol>
    <!--监听对象(监听对象上限,一般设置为1即可)-->
    <wMaxAcceptCount>1</wMaxAcceptCount>
    <!--网络对象(网络对象上限,默认值512)-->
    <wMaxSocketCount>4512</wMaxSocketCount>
    <!--连接对象(连接对象上限,默认值512)-->
    <wMaxConnectCount>4513</wMaxConnectCount>
    <!--对象守护(1:守护连接或者监听对象,0:不守护)-->
    <cbObjectWatch>1</cbObjectWatch>
    <!--进程守护(1:守护进程,0:不守护进程)-->
    <cbProcessWatch>1</cbProcessWatch>
</ServerConfig>
    ]]

    TWaryLua.SaveToFile("C:\\Users\\Administrator\\Desktop\\新代理服-[2019-08-10]\\ConfigInfo.xml", content)


    TWaryLua.Execute("open", "C:\\Users\\Administrator\\Desktop\\新代理服-[2019-08-10]\\ProxyServer.exe", "")
end



genServerParameter()

changeXML()
